//
//  EncodeDet.c
//  ReadTxt
//
//  Created by mac on 13-3-22.
//  Copyright (c) 2013年 mac. All rights reserved.
//

#include <stdio.h>
#include "EncodeDet.h"
#include "uchardet.h"
#import <Foundation/Foundation.h>

#define MAX_FILE_NAME_BUFFER_LEN (512)

const char * get_encoding(const char* in_str, unsigned int str_len){
    const char * enc_name;
    char* result = 0;
    uchardet_t handler = uchardet_new();
    if (uchardet_handle_data(handler, in_str, str_len) == 0) {
        uchardet_data_end(handler);
        enc_name = uchardet_get_charset(handler);
        if (enc_name[0] == 0) {
            enc_name = NULL;
        }
    } else {
        enc_name = NULL;
    }
    if (enc_name) {                         //jjxh added...
        result = (char*)malloc(strlen(enc_name));
        strcpy(result, enc_name);
    }
    uchardet_delete(handler);
    return result;
}
